package com.home.common;

import java.util.Date;
import java.util.Map;

import com.home.common.attributes.UserAttribute;
import com.home.common.util.CommonUtil;
import com.home.entity.User;
import com.opensymphony.xwork2.ActionContext;

public class BaseVO {
    public Date createTime;   // 创建时间
    public Date updateTime;   // 修改时间
    public String createBy;   // 创建人
    public String updateBy;   // 创建人
    
    public Date getCreateTime() {
        return getTime(createTime);
    }
    public void setCreateTime(Date createTime) {
        this.createTime = getTime(createTime);
    }
    public Date getUpdateTime() {
        return getTime(updateTime);
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = getTime(updateTime);
    }
    public String getCreateBy() {
        return getUser(createBy);
    }
    public void setCreateBy(String createBy) {
        this.createBy = getUser(createBy);
    }
    public String getUpdateBy() {
        return getUser(updateBy);
    }
    public void setUpdateBy(String updateBy) {
        this.updateBy = getUser(updateBy);
    }
    
    public Date getTime(Date time){
        if(time == null || "".equals(time)){
            return new Date();
        }
        return time;
    }
    
    public Date setTime(Date time){
        if(time == null || "".equals(time)){
            return new Date();
        }
        return time;
    }
    
    @SuppressWarnings("rawtypes")
    public String getUser(String userId){
        if(CommonUtil.isEmpty(userId)){
            Map session =  ActionContext.getContext().getSession();
            User user = (User) session.get(UserAttribute.SESSION_USER);
            return user.getUserId();
        }
        return userId;
    }
}
